﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master_form.master" AutoEventWireup="true" CodeFile="xet_tuyen.aspx.cs" Inherits="App_Form_DanhMuc_Dantoc" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">

        Ext.require([
        'Ext.selection.CellModel',
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*',
        'Ext.grid.Panel'
        ]);

        Ext.onReady(function () {

            Ext.QuickTips.init();

            var bd = Ext.getBody();

            var gridForm = Ext.create('Ext.form.Panel',
            {
                id: 'companyform',
                frame: true,
                bodyPadding: 5,
                layout:
                {
                    type: 'table',
                    columns: 2
                },
                fieldDefaults:
                {
                    labelAlign: 'left',
                    msgTarget: 'side'
                },

                items:
                [
                    {
                        columnWidth: '40%',
                        margin: '0 5 0 10',
                        xtype: 'fieldset',
                        title: 'Thông tin chính',
                        defaults:
                        {
                            width: 300,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items:
                        [
                            {
                                xtype: 'hidden',
                                id: 'id_ts',
                                name: 'id_ts'
                            },
                            {
                                xtype: 'combo', emptyText: 'Chọn năm tuyển sinh', fieldLabel: 'Năm TS',
                                triggerAction: 'all', forceSelection: true, editable: false,
                                id: 'nam_hoc', name: 'nam_hoc', displayField: 'ten',
                                valueField: 'id', queryMode: 'local',
                                listeners: {
                                    select: function (combo, record, index) {
                                        if (record.length > 0) {
                                            var id_nam = record[0].get('id'),
                                                b_khoi = Ext.getCmp("khoithi").getValue();
                                            //Goi service
                                            wsinh_vien.Fs_TT_TUYEN_SINH_TIM(id_nam, b_khoi, tt_tuyen_sinh_tim_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                }
                            },
                            {
                                xtype: 'combo', value: '', triggerAction: 'all', emptyText: 'Chọn khối thi', fieldLabel: 'Khối thi',
                                forceSelection: true, editable: false, id: 'khoithi',
                                name: 'khoithi', displayField: 'Ten', valueField: 'Ma_khoi',
                                listeners: {
                                    select: function (combo, record, index) {
                                        if (record.length > 0) {
                                            var id_nam = Ext.getCmp("nam_hoc").getValue(),
                                            b_khoi = record[0].get('Ma_khoi');
                                            //Goi service
                                            wsinh_vien.Fs_TT_TUYEN_SINH_TIM(id_nam, b_khoi, tt_tuyen_sinh_tim_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                }
                            },
                            {
                                xtype: 'combo', triggerAction: 'all', fieldLabel: 'Bộ môn',
                                emptyText: 'Chọn bộ môn', forceSelection: true, editable: false,
                                id: 'bo_mon', name: 'bo_mon', displayField: 'TenNganh', valueField: 'Id_Nganh', store: null,
                                listeners: {
                                    select: function (combo, record, index) {
                                        if (record.length > 0) {
                                            var id_nganh = record[0].get('Id_Nganh');
                                            //Goi service
                                            wdkhp.Fs_NganhDT(id_nganh, P_MON_NGANH_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                }
                            },
                            {
                                xtype: 'combo', triggerAction: 'all', emptyText: 'Chọn bộ ngành', fieldLabel: 'Ngành ĐT',
                                forceSelection: true, editable: false, id: 'nganhdt', name: 'nganhdt',
                                displayField: 'ten', valueField: 'id_nganhdt'
                            },
                            {
                                xtype: "numberfield", id: 'so_sv', fieldLabel: 'Số Sinh viên',
                                name: 'so_sv', allowNegative: false, hideTrigger: true
                            },
                            {
                                xtype: "numberfield", tooltip: 'Số sinh viên trên phòng thi', id: 'diem_dk', fieldLabel: 'Điểm dự kiến',
                                name: 'diem_dk', allowNegative: false, hideTrigger: true, value: '0'
                            },
                            {
                                xtype: 'fieldcontainer',
                                combineErrors: true,
                                layout:
                                    {
                                        type: 'hbox',
                                        defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                    },
                                items:
                                [
                                    {
                                        name: 'add',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/add.gif',
                                        text: 'Thêm mới',
                                        // Click
                                        handler: function () {
                                            var form = this.up('form').getForm();
                                            if (form.isValid()) {
                                                var
                                                b_ma = Ext.getCmp('id_ts').getValue(), b_khoi_thi = Ext.getCmp('khoithi').getValue(),
                                                b_nganhdt = Ext.getCmp('nganhdt').getValue(), b_so_sv = Ext.getCmp('so_sv').getValue(),
                                                b_diem_dk = Ext.getCmp('diem_dk').getValue(), b_nam = Ext.getCmp('nam_hoc').getValue();
                                                if (b_so_sv == "" || b_so_sv == undefined) return alert("Chưa nhập số lượng tuyển dự kiến");
                                                wsinh_vien.Fs_TT_TUYEN_SINH_NH(b_ma, b_nam, b_nganhdt, b_khoi_thi, b_so_sv, b_diem_dk, tt_tuyen_sinh_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                            }
                                        }
                                    },
                                    {
                                        name: 'moi',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/refesh.png',
                                        text: 'Mới',
                                        handler: function () {
                                            Ext.getCmp('diem_dk').reset();
                                            Ext.getCmp('nganhdt').reset();
                                            Ext.getCmp('so_sv').reset();
                                        }
                                    },
                                    {
                                        name: 'moi',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/delete.gif',
                                        text: 'Xóa',
                                        handler: function () {
                                            var c = confirm("Bạn có chắc chắn xóa không ?"); if (!c) return;
                                            var b_ma = Ext.getCmp("id_ts").getValue();
                                            if (b_ma == '' || b_ma == undefined) { return alert("Chưa chọn xóa") };
                                            wsinh_vien.Fs_TT_TUYEN_SINH_XOA(b_ma, tt_tuyen_sinh_xoa_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        xtype: 'gridpanel',
                        margin: '0 0 0 1',
                        id: 'ds_ts',
                        width: 400,
                        height: 400,
                        title: 'Danh sách',
                        columns: [
                            { id: 'MA1', flex: 1, text: 'Mã', width: 90, sortable: true, hidden: true, dataIndex: 'id_ts' },
                            { id: 'nganh1', text: 'Ngành', width: 300, flex: 1, sortable: true, dataIndex: 'nganh' },
                            { id: 'so_luong1', text: 'SL. Tuyển', width: 120, sortable: true, dataIndex: 'sl' },
                            { id: 'diem_dk1', text: 'Điểm DK', width: 100, sortable: true, dataIndex: 'diem' }
                        ],
                        listeners: {
                            selectionchange: function (model, records) {
                                if (records[0]) {
                                    var id_ts = records[0].get("id_ts");
                                    wsinh_vien.Fs_TT_TUYEN_SINH_CT(id_ts, tt_tuyen_sinh_ct_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                }
                            }
                        }
                    }
                ],
                renderTo: bd
            });
            wsinh_vien.Fs_XET_TUYEN_TTCHUNG(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
        });

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        function P_LOAD_TTCHUNG(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var a_kq = b_kq.split('@');
            var b_chuoi1 = CH_JSON(a_kq[0]);
            var a_data1 = Ext.create('Ext.data.Store', {
                fields: ['id', 'ten'],
                data: b_chuoi1
            });
            var cd = Ext.getCmp('nam_hoc');
            cd.bindStore(a_data1);

            var b_chuoi2 = CH_JSON(a_kq[2]);
            var a_data2 = Ext.create('Ext.data.Store', {
                fields: ['Id_Nganh', 'TenNganh'],
                data: b_chuoi2
            });

            var a = Ext.getCmp('bo_mon');
            a.bindStore(a_data2);

            var b_chuoi3 = CH_JSON(a_kq[1]);
            var a_data3 = Ext.create('Ext.data.Store', {
                fields: ['Ma_khoi', 'Ten'],
                data: b_chuoi3
            });

            var b = Ext.getCmp('khoithi');
            b.bindStore(a_data3);
        }
        function tt_tuyen_sinh_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var a_kq = b_kq.split('@');
            Ext.getCmp("id_ts").setValue(a_kq[0]);
            tt_tuyen_sinh_tim_P_KQ(a_kq[1]);
        }
        function tt_tuyen_sinh_tim_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }

            var b_chuoi = CH_JSON(b_kq);
            var a_data = Ext.create('Ext.data.Store', {
                fields: ['id_ts', 'nganh', 'sl', 'diem'],
                data: b_chuoi
            });

            Ext.getCmp('ds_ts').bindStore(a_data);
        }
        function P_MON_NGANH_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi = CH_JSON(b_kq);

                var a_data = Ext.create('Ext.data.Store', {
                    fields: ['id_nganhdt', 'ten'],
                    data: b_chuoi
                });

                var b = Ext.getCmp('nganhdt');
                b.clearValue();
                b.setValue("");
                b.setValue(null);
                b.bindStore(a_data);
            }
        }
        function tt_tuyen_sinh_xoa_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var grid = Ext.getCmp("ds_ts");
            var record = grid.getSelectionModel().getSelection();
            grid.store.remove(record[0], true);
        }
        function tt_tuyen_sinh_ct_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }

            var a_kq = b_kq.split("@");
            var b_chuoi = CH_JSON(a_kq[0]);
            P_MON_NGANH_KQ(a_kq[1]);
            var a_data = Ext.create('Ext.data.Store', {
                fields: ['id_ts', 'nam_hoc', 'khoithi', 'nganhdt', 'so_sv', 'diem_dk', 'bo_mon'],
                data: b_chuoi
            });

            Ext.getCmp("companyform").getForm().loadRecord(a_data.data.items[0]);
        }
    </script>
</asp:Content>

